#define _CRT_SECURE_NO_WARNINGS 1

#include"Heap.h"

void test()
{
    Heap hp;
    HeapInit(&hp);
    HeapPush(&hp, 1);
    HeapPush(&hp, 2);
    HeapPush(&hp, 3);
    HeapPush(&hp, 4);
    HeapDestroy(&hp);

}

void test1()
{
    int arr[] = { 1,2,3,4,5,10,9,8,7,6 }, len = 0, i = 0;
    len = sizeof(arr) / sizeof(arr[0]);
    Heap hp;
    HeapInit(&hp);
    for (i = 0; i < len; i++)
    {
        HeapPush(&hp, arr[i]);
    }
    i = 0;
    while (!HeapEmpty(&hp))
    {
        arr[i++] = HeapTop(&hp);
        HeapPop(&hp);
    }
    for (i = 0; i < len; i++)
    {
        printf("%d ", arr[i]);
    }
}

void HeapSort(int* arr, int n)
{
    int i = 0;
    for (i = (n - 1 - 1) / 2; i >= 0; i--)
    {
        AdjustDown(arr, i, n);
    }
    int end = n - 1;
    while (end > 0)
    {
        int temp = arr[0];
        arr[0] = arr[end];
        arr[end] = temp;
        AdjustDown(arr, 0, end--);
    }
}

int main()
{
    test1();
    int arr[] = { 1,6,2,5,3,4 };
    HeapSort(arr, 6);
    //test();
    return 0;
}